﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinCourseControls
{
    public partial class FrmDialog : Form
    {
        public FrmDialog()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 选择字体对话框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if(fontDialog1.ShowDialog()==DialogResult.OK)
            {
                label1.Font = fontDialog1.Font;  // 设置字体
                label1.ForeColor = fontDialog1.Color;
            }
        }

        /// <summary>
        /// 选择颜色对话框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                // 设置当前窗体的前景色
                this.ForeColor = colorDialog1.Color;//用户选定的颜色
                groupBox1.ForeColor = colorDialog1.Color;  // groupBox控件的前景色需要单独设置
            }
        }
        
        /// <summary>
        /// 选择颜色对话框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                this.BackColor = colorDialog1.Color;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.BackColor = colorDialog1.Color;
            }
        }

        /// <summary>
        /// 打开选择文件对话框-这个是控件形式的，还有代码形式的。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //txtFilePath.Text = openFileDialog1.FileName;//选择单个- 文件的路径 
                txtFilePath.Text = string.Join(";",openFileDialog1.FileNames);// 选择多个-文件的路径 
                string fileName = Path.GetFileName(openFileDialog1.FileNames[0]);//路径中的文件名和扩展名
            }
        }

        /// <summary>
        /// 保存文件对话框 - 这个是控件形式的，还有代码形式的
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveFile_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string file = saveFileDialog1.FileName;//选择的文件名
                string fileName = Path.GetFileName(file);//路径中的文件名和扩展名
                //已存在的文件删除
                if(File.Exists(file))
                {
                    File.Delete(file);
                }
                File.Copy(txtFilePath.Text, file);
            }
        }

        /// <summary>
        /// 选择文件夹路径按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnChoose_Click(object sender, EventArgs e)
        {
            if(folderBrowserDialog1.ShowDialog()==DialogResult.OK)
            {
                txtPath.Text = folderBrowserDialog1.SelectedPath;//选择的文件夹
            }
        }

        /// <summary>
        /// 提交按钮-保存到选择的文件夹下
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            string fileName = Path.GetFileName(txtFilePath.Text);//路径中的文件名和扩展名
            File.Copy(txtFilePath.Text, Path.Combine(txtPath.Text , fileName));
        }

      
    }
}
